package com.somnus.androidkotlindemo.databinding

import android.databinding.DataBindingUtil
import android.databinding.ViewDataBinding
import android.view.ViewGroup
import com.android.databinding.library.baseAdapters.BR
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder

/**
 * Created by Somnus on 2019/5/28.
 */
abstract class DataBindingAdapter<T>(resId: Int) : BaseQuickAdapter<T, BindingViewHolder<ViewDataBinding>>(resId) {

    override fun onCreateDefViewHolder(parent: ViewGroup?, viewType: Int): BindingViewHolder<ViewDataBinding>? {
        val databinding = DataBindingUtil.inflate<ViewDataBinding>(mLayoutInflater, mLayoutResId, parent, false)
        return BindingViewHolder(databinding)
    }

    override fun onBindViewHolder(holder: BindingViewHolder<ViewDataBinding>, position: Int) {
//        val dataBing = DataBindingUtil.bind<ViewDataBinding>(holder.itemView)
//        dataBing.setVariable(BR.item, mData.get(position))
//        dataBing.executePendingBindings()

        val binding = holder.binding
        binding.setVariable(BR.item, mData.get(position))
        binding.executePendingBindings()
    }



//    override fun onBindViewHolder(holder: BaseViewHolder, position: Int) {
//        val dataBing = DataBindingUtil.bind<ViewDataBinding>(holder.itemView)
//        dataBing.setVariable(BR.item, mData.get(position))
//        dataBing.executePendingBindings()
//
//    }




}